<?php
require('common_view_functions.php');

function show_comment_author($author_name, $url) {
	if(strlen($url) > 0) {
		return ' <a href="' . $url . '" target="_blank">' . htmlspec($author_name) . '</a>';
	} else {
		return htmlspec($author_name);
	}
}

$show_my_emotag = FALSE;
// emoTag wrapper proc
if(strpos($blog_info->announcement, '[emoTag]') !== FALSE) {
	$ett = '<div id="emoTagsWrapper"></div>';
	$ett .= '<div id="emoTagPagingPanel">';
	$ett .= '<a href="javascript:;" rel="prev">&laquo;</a>';
	$ett .= '<span>Loading...</span>';
	$ett .= '<a href="javascript:;" rel="next">&raquo;</a>';
	$ett .= '</div>';
	$blog_info->announcement = str_replace('[emoTag]', $ett, $blog_info->announcement);
	$show_my_emotag = TRUE;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><?php echo(htmlspec($entry_info->title . ' - ' . $blog_info->title)); ?></title>

<link rel="shortcut icon" href="/img/favicon.ico" />

<link rel="stylesheet" type="text/css" media="screen" href="/css/themes/<?php echo($blog_info->skin_name); ?>/styles.css" />
<link rel="stylesheet" type="text/css" media="print" href="/css/print.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
<link rel="stylesheet" type="text/css" href="/css/expressions.css" />
<link rel="stylesheet" type="text/css" href="/css/emotag.css" />
<link rel="stylesheet" type="text/css" href="/css/widgets.css" />
<link rel="stylesheet" type="text/css" href="/css/ubb_more.css" />
</head>

<body>
<?php require('ie_warning.php') ?>
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	
	<div id="body">
		<div id="main">
			<div id="jumper">
				<?php if(!is_null($prev_entry_info)) { ?>
				<div id="prev_entry">&laquo; 前一篇：<a href="<?php echo('/' . $blogger_uri . '/entry/' . $prev_entry_info->id); ?>"><?php echo(htmlspec($prev_entry_info->title)); ?></a></div>
				<?php } else { ?>
				<div id="prev_entry">&laquo; 没有更老的网志了</div>
				<?php } ?>
				<?php if(!is_null($next_entry_info)) { ?>
				<div id="next_entry">后一篇：<a href="<?php echo('/' . $blogger_uri . '/entry/' . $next_entry_info->id); ?>"><?php echo(htmlspec($next_entry_info->title)); ?></a> &raquo;</div>
				<?php } else { ?>
				<div id="next_entry">没有更新的网志了 &raquo;</div>
				<?php } ?>
				<div class="z"></div>
			</div>
			<div id="entries">
				<div class="entry">
					<h3 class="expr_<?php echo($entry_info->expression); ?>">
						<?php if($entry_info->id > 0) { ?>
						<?php echo(htmlspec($entry_info->title)); ?>
						<?php } else { ?>
						<?php echo($entry_info->state == 0 ? '保密网志' : '社区内部网志'); ?>
						<?php } ?>
						<span>@ <?php echo(date_part($entry_info->post_time)); ?></span>
					</h3>
					
					<?php if($current_user_id > 0) { ?>
						<div class="watch"><a href="javascript:;" rel="w_<?php echo($entry_info->id); ?>"><img alt="关注此帖" src="/img/star.png" title="关注此帖" /></a></div>
					<?php } ?>
					
					<div class="cate">
						<?php if($entry_info->id > 0) { ?>
						<?php echo(htmlspec($entry_info->category_title)); ?>
						<?php } else { echo('N/A'); } ?>
					</div>
					
					<div class="content<?php echo(entry_state_indicator($entry_info->state)); ?>">
						<?php echo($entry_info->content); ?>
					</div>
					
					<div class="tags">
						<?php echo(make_tag_links($entry_info->tags, $blogger_uri)); ?>
						<div class="z"></div>
					</div>
					
					<div class="info">
						<?php if($is_blog_owner) { ?>
						<input type="button" id="e_<?php echo($entry_info->id); ?>" class="editEntryButton" value="编辑" />
						<?php } ?>
						发布于 <?php echo($entry_info->post_time); ?>
						|
						<?php if($entry_info->id > 0) { ?>
						<a href="<?php echo('/' . $blogger_uri . '/entry/' . $entry_info->id . '#comments'); ?>">评论：<strong><?php echo($entry_info->comment_num); ?></strong></a>
						<?php } else { echo('评论：N/A'); } ?>
					</div>
				</div>
				
			</div><!-- /entries -->
			
			<?php if(($is_blog_owner) || ($entry_info->state == 1) || ($entry_info->state == 0 && $is_blog_friend) || ($entry_info->state == 3 && $is_community_member)) { ?>
			<div id="comments">
				<div id="comments_wrapper">
				<?php
				$is_odd = TRUE;
				foreach($comments as $cmt) {
				?>
				<div id="c<?php echo($cmt->id); ?>" class="comment <?php echo($is_odd ? 'odd' : 'even'); ?>">
					<div class="a"><img alt="" src="<?php echo(base_url() . 'img/avatars/' . get_avatar_name($cmt->by_blogger_id)); ?>" /></div>
					<div class="c">
						<div class="i">
							<?php echo(show_comment_author($cmt->author_name, $cmt->url) . ' @ ' . $cmt->post_time . $cmt->ip); ?><?php if($is_blog_owner) { ?> <input type="button" id="d_<?php echo($cmt->id); ?>" value="删" class="deleteCommentButton" /><?php } ?>
						</div>
						<?php echo($cmt->content); ?>
					</div>
				</div>
				<?php
					$is_odd = !$is_odd;
				}
				?>
				</div><!-- /comments_wrapper -->
				
				<?php if($entry_info->allow_comment) { ?>
				<h4>看帖要回帖...</h4>
				<form id="frmPostCommentBox">
					<label for="txtAuthorName">你的大名：<span class="hint"><?php if($current_user_id > 0) { echo('Logged in as ' . htmlspec($current_user_name)); } ?></span></label>
					<input type="text" id="txtAuthorName" class="textBox cmtInput" value="<?php echo($last_comment_name); ?>" maxlength="16" />
					
					<label for="txtEmail">E-mail：<span class="hint">非必填，不会对外公开</span></label>
					<input type="text" id="txtEmail" class="textBox cmtInput" maxlength="64" value="<?php echo($last_comment_email); ?>" />
					
					<label for="txtUrl">你的 Blog：<span class="hint">非必填，请包含 http:// 前缀</span></label>
					<input type="text" id="txtUrl" class="textBox cmtInput" maxlength="128" value="<?php echo($last_comment_url); ?>" />
					
					<label for="txtCommentContent">说点什么：<span class="hint">评论发表后无法修改，请注意错别字等</span></label>
					<textarea id="txtCommentContent" class="textBox"></textarea>
					
					<input type="button" id="btnPostComment" class="button" value="发表" />
					<img id="imgWaitComment" alt="Loading" src="/img/ajax-loader.gif" border="0" width="43" height="11" style="vertical-align:middle;display:none;" />
					<input type="hidden" id="hidCurrentEntryId" value="<?php echo($entry_info->id); ?>" />
				</form>
				<?php } else { ?>
				<h4 style="color:#000;">评论已关闭！</h4>
				<?php } ?>
			</div><!-- /comments -->
			<?php } ?>
		</div><!-- /main -->
		
		<div id="side">
			
			<div id="ann"><?php echo($blog_info->announcement); ?></div>
			
			<dl class="block">
				<dt>categories</dt>
				<dd>
					<ul>
						<li><a href="<?php echo('/' . $blogger_uri); ?>/rss/1"><img alt="" src="/img/rss_icon_glass12.png" class="rssIconSmall" /></a> <a href="<?php echo('/' . $blogger_uri); ?>/category/1">未分类</a></li>
						<?php foreach($custom_categories as $cate) { ?>
						<li><a href="<?php echo('/' . $blogger_uri . '/rss/' . $cate->id); ?>"><img alt="" src="/img/rss_icon_glass12.png" class="rssIconSmall" /></a> <a href="<?php echo('/' . $blogger_uri . '/category/' . $cate->id); ?>"><?php echo(htmlspec($cate->title)); ?></a></li>
						<?php } ?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block" id="arc_list">
				<dt>archives</dt>
				<dd>
					<ul>
						<?php
						$the_year = 0;
						foreach($blog_archives as $arcy) {
							$year = $arcy->year;
							if($year == $the_year) {
								continue;
							} else {
						?>
						<li class="arc_year"><a href="javascript:;"><?php echo($year . '年'); ?></a>
							<ul>
								<?php
								foreach($blog_archives as $arc) {
									if($arc->year == $year) {
								?>
								<li><a href="<?php echo('/' . $blogger_uri . '/archive/' . $arc->year . '/' . $arc->month); ?>"><?php echo($arc->year . '年' . $arc->month . '月：' . $arc->num . '篇'); ?></a></li>
								<?php
									}
								}
								?>
							</ul>
						</li>
						<?php
							}
							$the_year = $year;
						}
						?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block">
				<dt>links</dt>
				<dd>
					<ul>
						<?php foreach($links as $lk) { ?>
						<li><a rel="friend" href="<?php echo($lk->url); ?>" target="_blank"><?php echo(htmlspec($lk->title)); ?></a><div class="link_desc"><?php echo(htmlspec($lk->description)); ?></div></li>
						<?php } ?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block">
				<dt>statistics</dt>
				<dd>
					<ul>
						<li>网志数：<?php echo($blog_info->entry_num); ?></li>
						<li>评论数：<?php echo(is_null($blog_info->comment_num) ? '0' : $blog_info->comment_num); ?></li>
					</ul>
				</dd>
			</dl>
		</div><!-- /side -->
		<div class="z"></div>
	
	</div><!-- /body -->
	
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
	
</div><!-- /wrapper -->

<!-- Common Widgets -->
<?php require('common_widgets.php'); ?>
<!-- /Common Widgets -->

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/jquery.autogrow.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";
var textAreaAutoExp = false; // 暂时去掉，用 IE 的 SB 太多了
// -->
</script>

<script type="text/javascript" src="/js/common.js"></script>

<script type="text/javascript">
<!--
<?php if($show_my_emotag) { ?>

function loadEmoTagList(pg) {
	$("#emoTagsWrapper").load(g_userSiteRoot + "/mgmt/emotag/" + pg, {
		"R": Math.random()
	}, function() {
		var pagingInfo = $("#hidEmoTagPaging").val();
		pagingInfo = pagingInfo.split("|");
		if(pagingInfo[1] == "1/0") {
			$("#emoTagPagingPanel").hide();
		} else {
			prevPg = pagingInfo[0];
			$("#emoTagPagingPanel span").text(pagingInfo[1]);
			nextPg = pagingInfo[2];
		}
		loadEmoTagPageDone = true;
	});
}

<?php } ?>

$(document).ready(function() {
	registerCommonEvents();
	
	// toggle archive (year) list
	$("#arc_list li.arc_year a").click(function() {
		$(this).parent().find("ul").toggle();
	});
	
	<?php if($show_my_emotag) { ?>
	
	$("#emoTagPagingPanel a").click(function() {
		if(!loadEmoTagPageDone) {
			return;
		}
		var way = $(this).attr("rel");
		$("#emoTagPagingPanel span").text("Loading...");
		if(way == "prev") {
			loadEmoTagList(prevPg);
		} else if(way == "next") {
			loadEmoTagList(nextPg);
		}
	});
	
	loadEmoTagList(0);
	
	<?php } ?>
	
	<?php require('common_skin_adapters.php'); ?>
	
});
// -->
</script>
<!-- /JS -->

</body>
</html>
